package samples.duty_chain_mode.handler;

import samples.duty_chain_mode.enums.DutyEnum;

public abstract class Handler {
    protected Handler nextHandler;
    private final DutyEnum dutyEnum;

    public Handler(DutyEnum dutyEnum) {
        this.dutyEnum = dutyEnum;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    public void handleRequest(DutyEnum dutyEnum) {
        if (dutyEnum.equals(this.dutyEnum)) {
            handle();
        } else {
            nextHandler.handle();
        }
    }

    protected abstract void handle();
}
